/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup CryptoKeyAgreementApi
 * @{
 *
 * @brief 为应用提供密钥协商算法接口。
 *
 * @since 20
 */

/**
 * @file crypto_key_agreement.h
 *
 * @brief 定义密钥协商接口。
 *
 * @library libohcrypto.so
 * @include <CryptoArchitectureKit/crypto_key_agreement.h>
 * @kit CryptoArchitectureKit
 * @syscap SystemCapability.Security.CryptoFramework
 * @since 20
 */

#ifndef CRYPTO_KEY_AGREEMENT_H
#define CRYPTO_KEY_AGREEMENT_H

#include "crypto_common.h"
#include "crypto_asym_key.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief 定义密钥协商结构。
 *
 * @since 20
 */
typedef struct OH_CryptoKeyAgreement OH_CryptoKeyAgreement;

/**
 * @brief 根据给定的算法名称创建密钥协商实例。
 *
 * @param algoName 用于生成密钥协商实例的算法名称。\n
 * 例如"ECC"、"X25519"。
 * @param ctx 密钥协商实例。
 * @return CRYPTO_SUCCESS：操作成功。\n
 *         CRYPTO_NOT_SUPPORTED：操作不支持。\n
 *         CRYPTO_MEMORY_ERROR：内存错误。\n
 *         CRYPTO_PARAMETER_CHECK_FAILED：参数检查失败。\n
 *         CRYPTO_OPERTION_ERROR：调用三方算法库API出错。
 * @since 20
 */
OH_Crypto_ErrCode OH_CryptoKeyAgreement_Create(const char *algoName, OH_CryptoKeyAgreement **ctx);

/**
 * @brief 生成密钥协商的秘密值。
 *
 * @param ctx 密钥协商实例。
 * @param privkey 私钥。
 * @param pubkey 公钥。
 * @param secret 秘密值。
 * @return CRYPTO_SUCCESS：操作成功。\n
 *         CRYPTO_NOT_SUPPORTED：操作不支持。\n
 *         CRYPTO_MEMORY_ERROR：内存错误。\n
 *         CRYPTO_PARAMETER_CHECK_FAILED：参数检查失败。\n
 *         CRYPTO_OPERTION_ERROR：调用三方算法库API出错。
 * @since 20
 */
OH_Crypto_ErrCode OH_CryptoKeyAgreement_GenerateSecret(OH_CryptoKeyAgreement *ctx, OH_CryptoPrivKey *privkey,
    OH_CryptoPubKey *pubkey, Crypto_DataBlob *secret);

/**
 * @brief 销毁密钥协商实例。
 *
 * @param ctx 密钥协商实例。
 * @since 20
 */
void OH_CryptoKeyAgreement_Destroy(OH_CryptoKeyAgreement *ctx);

#ifdef __cplusplus
}
#endif

#endif /* CRYPTO_KEY_AGREEMENT_H */
/** @} */
